// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class GUARANTOR_INSURANCE_RQA_I08 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("28 GT1",28)]
  	    [HL7Field(HL7Version.v23, 28, HL7Repeat.True, HL7Required.False,"GT1")]
	    public GT1[] GT1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("31 INSURANCE",31)]
  	    [HL7Field(HL7Version.v23, 31, HL7Repeat.True, HL7Required.True,"INSURANCE_RQA_I08")]
	    public INSURANCE_RQA_I08[] INSURANCE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			GT1 = PopSegmentParseAndCheckRequiredArray<GT1>(availableData, options, "GT1");
			INSURANCE = ProcessGroupArray<INSURANCE_RQA_I08>(availableData, options, "INSURANCE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isGT1 = availableData.StartsWith("GT1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("GT1", options.Version) || isGT1) {
				return isGT1;
			}
			INSURANCE_RQA_I08 testINSURANCE_RQA_I08 = new INSURANCE_RQA_I08();
			bool grpCCINSURANCE_RQA_I08 = (testINSURANCE_RQA_I08.CanConsume(availableData, options));
			if (IsRequired("INSURANCE", options.Version) || grpCCINSURANCE_RQA_I08) {
				return grpCCINSURANCE_RQA_I08;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "GUARANTOR_INSURANCE";
			}
        }

        static GUARANTOR_INSURANCE_RQA_I08() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(GUARANTOR_INSURANCE_RQA_I08));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (GT1 != null && GT1.Length > 0) {
			for (int i = 0; i < GT1.Length; i++) {
				string segmentValue = GT1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (INSURANCE != null && INSURANCE.Length > 0) {
			for (int i = 0; i < INSURANCE.Length; i++) {
				string segmentValue = INSURANCE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

